<?php defined('BASEPATH') OR exit('No direct script access allowed');

class docket extends CI_Controller {

	function __construct()
	{
		parent::__construct();
		
		if (!$this->ion_auth->logged_in())
		{
			//redirect them to the login page
			redirect('auth/login', 'refresh');
		}
		elseif (!$this->ion_auth->is_admin())
		{
			//redirect them to the home page because they must be an administrator to view this	
			redirect('/', 'refresh');
		}
		$this->load->model('docket_model');
        $this->load->library('datatables');			
	}
	function new_received()
	{
	$meta['page_title'] = 'New Docket Received';
		 $this->load->view('common/header',$meta);
	     $this->load->view('docket/dispatch_docket');
		 $this->load->view('common/footer');	
	}
	
	function new_dispatch()
	{
	  
				$sl_no = $this->input->post('sl_no');
				$case_no=$_REQUEST['case_no'];
			//	$case_id=$this->docket_model->get_case_id($case_no)->row();
			    $docket=$this->input->post('docket_no');
				$received=$this->input->post('received_date');
				$response=$this->input->post('response');
			    $length = count($sl_no);
				
					for($i=0; $i<$length; $i++){
						
						$data['case_no']=$case_no[$i];
						$id[$i]=$this->docket_model->get_case_id($case_no[$i])->row();
						
						$service[$i]=$this->docket_model->get_service_id($case_no[$i])->row();
						$data['docket_no']=$docket[$i];
				       $data['received_date']=$received[$i];
					   $data['response']=$response[$i];
				      $data['case_id'] =$id[$i]->id;
					
			        $this->docket_model->received_docket($data);
			        $this->docket_model->update_status($service[$i]->service_id);
					$this->docket_model->update_case_status($service[$i]->service_id);
						}							
             
                   redirect('admin/docket/view_notassigned');
	}
	function get_docket_no()
	{
	$case_no=$_REQUEST['id'];
	$data=$this->docket_model->get_docket($case_no)->row();
	
	if($data)
	{
	echo $data->docket_no;
	}
	else
	{
	echo "";
	}
	}
	
public function view_all()
{
$meta['page_title'] = 'ALL Docket Received';
$this->load->view('common/header',$meta);
$this->load->view('docket/all_docket');
 $this->load->view('common/footer');	


}
public function view_notassigned()
{
$meta['page_title'] = ' Docket Not Assigned';
$this->load->view('common/header',$meta);
$this->load->view('docket/not_assigned');
 $this->load->view('common/footer');	


}
public function notassigned_docket()
{
echo $this->docket_model->get_notassigned_view();

}

	
public function getall_docket()
{
echo $this->docket_model->get_disp_view();

}	
	
public function assigned_engineer($id)
{
$data['already_assign']=$this->docket_model->get_assign_details($id)->row();
 $data['engineer']=$this->docket_model->get_engineer();
 $case=$this->docket_model->get_case_no($id)->row();
 $data['case_no']=$case->case_no;
 $data['service_id']=$this->docket_model->get_service_id($data['case_no'])->row();
 $data['case_id']=$case->case_id;
 $data['docket_no']=$case->docket_no;
$meta['page_title'] = 'Assigned Engineer';
$this->load->view('common/header',$meta);
$this->load->view('docket/assigned_engineer',$data);
 $this->load->view('common/footer');	


}	
public function place_order()
{

echo "hello";



}	
	
	
	
	
	
	}